This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Fix stale function reference when calling context menu handler#1072
Merged
BinaryMuse merged 1 commit intomasterfrom Aug 2, 2017
Merged
Fix stale function reference when calling context menu handler#1072BinaryMuse merged 1 commit intomasterfrom
BinaryMuse merged 1 commit intomasterfrom
Conversation
Upon mounting, ContextMenuInterceptor retained the onWillShowContextMenu prop as a direct function reference; when updating the component with a new onWillShowContextMenu, the retained function was not updated. As a result, right-clicking on the wrapped element could potentially call a previously-passed value of onWillShowContextMenu. The solution is to instead retain a function that has dynamic access to the latest onWillShowContextMenu prop.
smashwilson
approved these changes
Aug 1, 2017
Contributor
smashwilson
left a comment
There was a problem hiding this comment.
Oh hey, this is definitely a subtlety I have not thought of before.
Think we should do a quick search for passing this.props directly to event handlers elsewhere in the codebase?
BinaryMuse
pushed a commit
that referenced
this pull request
Aug 2, 2017
Fix stale function reference when calling context menu handler (cherry picked from commit 7f5b767)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #885
Upon mounting, ContextMenuInterceptor retained the onWillShowContextMenu
prop as a direct function reference; when updating the component with
a new onWillShowContextMenu, the retained function was not updated. As
a result, right-clicking on the wrapped element could potentially call
a previously-passed value of onWillShowContextMenu. The solution is to
instead retain a function that has dynamic access to the latest
onWillShowContextMenu prop.
An alternative solution was to update the retained function in a
componentDidUpdate hook, but by registering a function that has
the ability to look up the prop dynamically, this hook isn't necessary.